<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="title">ABCD的灰色条状颜色是一样的颜色吗？</div>
    <input type="button" value="切换颜色" onclick="change()">
    <div class="cols">
        <div class="col">
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="text">A</div>
        </div>
        <div class="col">
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="text">B</div>
        </div>
        <div class="col">
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="text">C</div>
        </div>
        <div class="col">
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="row1"></div>
            <div class="row2"></div>
            <div class="text">D</div>
        </div>
    </div>
    <script>
        function change(){
            var a = document.querySelectorAll(".cols .col:nth-child(1) .row2");
            var b = document.querySelectorAll(".cols .col:nth-child(4) .row2");
            a.forEach((v,i)=>v.style.backgroundColor=getComputedStyle(v).backgroundColor==="rgb(0, 0, 0)"?"#ffffff":"#000000");
            b.forEach((v,i)=>v.style.backgroundColor=getComputedStyle(v).backgroundColor==="rgb(0, 0, 0)"?"#ffffff":"#000000");
        }
    </script>
</body>

</html>